package cn.bone.admin.base.configuration;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Morphia;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by Administrator on 2017/9/11.
 */
@Configuration
public class MongoConfig {

    String url = "mongodb://vueAdmin:superbone@118.178.225.7:17017/vueAdmin";
    String dbName = "vueAdmin";

    @Bean
    public MongoClient mongoClient(){
        MongoClientURI mongoClientURI = new MongoClientURI(url);
        MongoClient client = new MongoClient(mongoClientURI);
        return client;
    }

    @Bean
    public Datastore datastore(){
        Morphia morphia = new Morphia();
        morphia.mapPackage("cn.bone.**");
        MongoClient client = mongoClient();
        Datastore datastore = morphia.createDatastore(client,dbName);
        return datastore;
    }
}
